package technology.JVM.JVM;

import java.lang.ref.PhantomReference;
import java.lang.ref.ReferenceQueue;

public class PhantomRefer {
    public static void main(String[] args) throws InterruptedException {
        ReferenceQueue<String> queue = new ReferenceQueue<String>();
        PhantomReference<String> pr = new PhantomReference<String>(new String("hello"), queue);
        System.out.println("pr.get(): " + pr.get());   // null
        System.gc();
        Thread.sleep(1000); // 等gc 完成
        System.out.println(queue.poll());    //java.lang.ref.PhantomReference@8efb846
        }
}
